requirejs.config({
  paths: {
    jquery: "//apps.bdimg.com/libs/jquery/2.1.4/jquery.min"
  }
}),


define(['jquery'],function($){
 
  function TimerBtn (){
    let $btn = $('<input type="button" class="timer-button">'),
      cfg = {
        container: 'body',
        title: '同意',
        delay: 6,
        enable: false,
        onClick: null

      },
      delay = 6,
      timer = null;

    $btn.css({
      height: '50px',
      width: '150px',
      'font-size': '1.2em'
    });


    this.show=function(config){
    // gen dom

      $.extend(cfg,config);
      $(cfg.container).append($btn);

      $btn.val(cfg.title+'（'+ cfg.delay + 's)');
      $btn.attr('disabled','disabled');

      timer = setInterval(()=>{

        $btn.val(cfg.title + '（'+ --delay + 's)');
        if(delay == 0){
          clearInterval(timer);
          $btn.val('同意');
          $btn.removeAttr('disabled');
        }
      },1000);


    // event bind
      $btn.click(cfg.onClick);
    }

    this.destroy=function(){
      $btn.remove();
    }
  }
return TimerBtn;

});  

